<template>
  <div class="login_container">
    <div class="login_box">
      <!-- 头像区域 -->
      <div class="avatar_box">
        <img src="../assets/logo.png" alt="">
      </div>
      <el-form
        :rules="rulesForm"
        :model="formData"
        status-icon
        label-width="100px"
        class="login_form"
        ref="qq"
      >
        <el-form-item label="密码" prop="username">
          <el-input
            v-model="formData.username"
            prefix-icon="el-icon-delete"
            type="text"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="password">
          <el-input
            v-model="formData.password"
            prefix-icon="iconfont icon-user"
            type="password"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="formSubmit">提交</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
           
<script>
import  {loginApi} from  '@/api'
export default {
  data() {
    return {
      formData: {
        username: "admin",
        password: "123456"
      },
      rulesForm: {
        username: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 10, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ]
      }
    };
  },

  methods: {
    reset() {
      this.$refs.qq.resetFields();
      // console.log(this.$refs.qq.resetFields(),888);
    },

    /* 提交 */
    formSubmit() {
      this.$refs.qq.validate(async vv => {
        //console.log(vv,777);
        if (!vv) return;
        // const { data: res } = await this.$http.post("login", this.formData);
        const { data: res } = await loginApi(this.formData)
        console.log(res);
        if (res.meta.status == 200) {
          this.$message({
            message: "恭喜你，这是一条成功消息",
            type: "success"
          });
        } else {
          this.$message({
            message: "登录失败",
            type: "warning"
          });
        }
        

      });
    }
  }
};
</script>
<style lang="less" scoped>
.login_container {
  background-color: #2b4b6b;
  height: 100%;
}

.login_box {
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  .avatar_box {
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eee;
    }
  }
}

.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}

.btns {
  display: flex;
  justify-content: flex-end;
}
</style>